﻿Public Class DadicionalesProforma

    Public Shared Function SeleccionarTodo(ByVal descEmpresa As String) As List(Of EadicionalesProforma)
        Dim adicionales As List(Of EadicionalesProforma) = Nothing

        Using cn As New SqlConnection(ConfigurationManager.ConnectionStrings(descEmpresa).ConnectionString)
            Using cmd As New SqlCommand("usp_adicionalInteres_sel", cn)
                cmd.CommandType = CommandType.StoredProcedure
                Try
                    cn.Open()
                    Using dr As SqlDataReader = cmd.ExecuteReader(CommandBehavior.SingleResult Or CommandBehavior.CloseConnection)
                        If dr.HasRows Then
                            adicionales = New List(Of EadicionalesProforma)
                            Dim adicional As EadicionalesProforma = Nothing
                            Do While dr.Read
                                adicional = New EadicionalesProforma( _
                                    dr.GetInt32(dr.GetOrdinal("idProforma")), _
                                    dr.GetInt32(dr.GetOrdinal("idAdicionalProforma")), _
                                    dr.GetString(dr.GetOrdinal("descConceptoAdicional")), _
                                    dr.GetDecimal(dr.GetOrdinal("monto")), _
                                    dr.GetString(dr.GetOrdinal("estado")))
                                adicionales.Add(adicional)
                            Loop
                            dr.Close()
                        End If
                    End Using
                Catch ex As Exception
                    Throw
                End Try
            End Using
        End Using

        Return adicionales
    End Function
    Public Shared Function Añadir(ByVal descEmpresa As String, ByVal padicional As EadicionalesProforma) As Boolean
        Dim resultado As Boolean = False

        Using cn As New SqlConnection(ConfigurationManager.ConnectionStrings(descEmpresa).ConnectionString)
            Using cmd As New SqlCommand("usp_adicionalInteres_add", cn)
                cmd.CommandType = CommandType.StoredProcedure
                cmd.Parameters.Add("@idProforma", SqlDbType.Int).Value = padicional.idProforma
                cmd.Parameters.Add("@descConceptoAdicional", SqlDbType.VarChar, 55).Value = padicional.descConceptoAdicional
                cmd.Parameters.Add("@monto", SqlDbType.Decimal, 15, 2).Value = padicional.monto
                cmd.Parameters.Add("@idUsuario", SqlDbType.Int).Value = padicional.idUsuario
                Try
                    cn.Open()
                    cmd.ExecuteNonQuery()
                    resultado = True
                Catch ex As Exception
                    Throw
                End Try
            End Using
        End Using

        Return resultado
    End Function
    Public Shared Function Editar(ByVal descEmpresa As String, ByVal pAdicional As EadicionalesProforma) As Boolean
        Dim resultado As Boolean = False

        Using cn As New SqlConnection(ConfigurationManager.ConnectionStrings(descEmpresa).ConnectionString)
            Using cmd As New SqlCommand("usp_adicionalInteres_edit", cn)
                cmd.CommandType = CommandType.StoredProcedure
                cmd.Parameters.Add("@idProforma", SqlDbType.Int).Value = pAdicional.idProforma
                cmd.Parameters.Add("@idAdicionalProforma", SqlDbType.Int).Value = pAdicional.idAdicionalProforma
                cmd.Parameters.Add("@descConceptoAdicional", SqlDbType.VarChar, 55).Value = pAdicional.descConceptoAdicional
                cmd.Parameters.Add("@monto", SqlDbType.Decimal, 15, 2).Value = pAdicional.monto
                cmd.Parameters.Add("@idUsuario", SqlDbType.Int).Value = pAdicional.idUsuario
                Try
                    cn.Open()
                    cmd.ExecuteNonQuery()
                    resultado = True
                Catch ex As Exception
                    Throw
                End Try
            End Using
        End Using

        Return resultado
    End Function
    Public Shared Function Eliminar(ByVal descEmpresa As String, ByVal padicional As EadicionalesProforma) As Boolean
        Dim resultado As Boolean = False

        Using cn As New SqlConnection(ConfigurationManager.ConnectionStrings(descEmpresa).ConnectionString)
            Using cmd As New SqlCommand("usp_adicionalInteres_del", cn)
                cmd.CommandType = CommandType.StoredProcedure
                cmd.Parameters.Add("@idProforma", SqlDbType.Int).Value = padicional.idProforma
                cmd.Parameters.Add("@idAdicionalProforma", SqlDbType.Int).Value = padicional.idAdicionalProforma
                cmd.Parameters.Add("@idUsuario", SqlDbType.Int).Value = padicional.idUsuario
                Try
                    cn.Open()
                    cmd.ExecuteNonQuery()
                    resultado = True
                Catch ex As Exception
                    Throw
                End Try
            End Using
        End Using

        Return resultado
    End Function

End Class
